package s.k.gui.webtest.basetools.file;

public class MyString {

	public String value;

	public MyString(String value) {

		this.value = value.trim();

	}

	/** ��ȡ��start��ʼ��end-1���ַ�� */
	public String pickUpStr(int start, int end) {

		StringBuilder val = new StringBuilder(this.value);

		if (start < 0)
			return null;

		if (start >= val.length() || end <= 0)
			return null;

		if (end > val.length())
			return null;

		if (start > end)
			return null;

		return val.substring(start, end);

	}

	/**
	 * ��ȡ��startSuffix��ʼ��endSuffix���ַ�ܣ����ǵ�һ�γ��ֵ��ַ��
	 * ���startSuffix=endSuffix����ôendSuffix���ǵڶ��γ��ֵ���Щ�ַ�
	 * ���startSuffix=null,��ô���شӿ�ʼ����һ��endSuffix�ַ��λ�õ������ַ�
	 * ���endSuffix=null,��ô���شӵ�һ��startSuffix�����������ַ�
	 */
	public String pickUpStr(String startSuffix, String endSuffix) {

		int start = 0, end = 0;

		if (startSuffix == null) {

			start = 0;

		} else {

			start = value.indexOf(startSuffix) + startSuffix.length();

		}
		if (endSuffix == null) {

			end = this.value.length();

		} else {

			end = start + value.substring(start).indexOf(endSuffix);

		}

		return pickUpStr(start, end);

	}

	public boolean includeAnd(String... args) {

		for (String arg : args) {

			if (value.contains(arg))

				continue;

			return false;

		}

		return true;

	}

	public boolean includeOr(String... args) {

		for (String arg : args) {

			if (value.contains(arg))

				return true;

			continue;
		}
		return false;
	}

	/** ���������κ�һ�� */
	public boolean notIncludeAnd(String... args) {

		for (String arg : args) {

			if (value.contains(arg))

				return false;

			continue;

		}
		return true;

	}

	/** ��������������һ������ */

	public boolean notIncludeOr(String... args) {

		for (String arg : args) {

			if (value.contains(arg))

				continue;

			return true;
		}

		return false;
	}

	/*** ȡ���˶������滹�е�args�ַ�ܣ����û�У���ȥ���еĻ�����ȥ��,����ж������ôһ��ȥ�� */
	public String subString(String... args) {

		for (String arg : args) {

			while (value.contains(arg)) {

				int start = value.indexOf(arg);

				value = value.substring(0, start)
						+ value.substring(start + arg.length(), value.length());

			}

		}
		return value;
	}

	/** ���Ǹ���toString���� */
	public String toString() {

		return this.value;
	}

	/** ��ӡ����ǰ��value */
	public void outValue() {

		System.out.println(this.toString());
	}

	/** ������һ����ͬ���򷵻�true */

	public boolean equalsOr(String... args) {

		for (String arg : args) {

			if (this.value.equalsIgnoreCase(arg))

				return true;

		}
		return false;

	}

	/** �������κ�һ����β������true */
	public boolean endsWithOr(String... args) {

		for (String arg : args) {

			if (this.value.endsWith(arg))

				return true;

		}
		return false;
	}

	public void replace(String oldSuffix, String newSuffix) {

		this.value = this.value.replace(oldSuffix, newSuffix);

	}

	public String[] split(String splitStr) {

		return this.value.split(splitStr);
	}

	public String getSplitPart(int index, String splitStr) {

		String[] splitResult = split(splitStr);

		if (index >= splitResult.length) {

			return null;

		}
		return splitResult[index];
	}

}
